//
//  YunZuanController.m
//  7.13苏宁框架
//
//  Created by mini on 15/7/26.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "YunZuanController.h"
#import "DSZMainViewController.h"
#import "Common.h"
#import "DSZLoginViewController.h"
@interface YunZuanController ()

@end

@implementation YunZuanController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    DSZMainViewController *main = (DSZMainViewController*)self.tabBarController;
    [main hiddenMainTabbar:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.smallView.showsHorizontalScrollIndicator = NO;
    self.smallView.pagingEnabled = YES;
    self.smallView.delegate =self;
    //给scrollView添加内容
    [self addImage];
    _pageController.numberOfPages = 3;
    //添加计时器
    [self addTimer];
    _bigScrollView.contentSize = CGSizeMake(320, 1430);
    NSString *name;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    name=[defaults objectForKey:@"zh2"];
    if ([name isEqualToString:@"disizu"]) {
        _logonView.hidden = YES;
    }
    else
    {
        _logonView.hidden = NO;
    }

}

-(void)addImage
{
    int x = 0;
    for (int i =0; i< 3 ; i++) {
        UIImageView *image = [[UIImageView alloc]init];
        NSString *str = [NSString stringWithFormat:@"10%d",i+3];
        image.image = [UIImage imageNamed:str];
        image.frame =CGRectMake(x, 0, _smallView.width, _smallView.height);
        [_smallView addSubview:image];
        x = x +320;
    }
    _smallView.contentSize = CGSizeMake(x, _smallView.height);
}

-(void)addTimer
{
    _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes];
}

-(void)changeImage
{
    if (_pageController.currentPage ==2) {
        _pageController.currentPage = 0;
    }
    else
    {
        _pageController.currentPage++;
    }
    _smallView.contentOffset = CGPointMake(_pageController.currentPage *320, 0);
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    //停止刷新计时器
    [_timer invalidate];
    _timer = nil;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int index = floor((_smallView.contentOffset.x + 320/2)/320);
    _pageController.currentPage = index;
    [self addTimer];
}
- (IBAction)loginClick {

    DSZLoginViewController *con = [[DSZLoginViewController alloc]init];
    [self.navigationController pushViewController:con animated:YES];
    _logonView.hidden = YES;
}
- (IBAction)returnClick {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (IBAction)closeClick {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (IBAction)moreClick {
    if (_backGroundView.hidden) {
        _backGroundView.hidden = NO;
        _homeView.hidden = NO;
        _refreshView.hidden = NO;
        _shareView.hidden = NO;
    }
    else
    {
        _backGroundView.hidden = YES;
        _homeView.hidden = YES;
        _refreshView.hidden = YES;
        _shareView.hidden = YES;
    }
}
- (IBAction)homeClick {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (IBAction)returnToTop {
    //[self.bigScrollView scrollRectToVisible:self.bigScrollView.frame animated:YES];
    [self.bigScrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
}
@end
